<?php
defined('_JEXEC') or die;

//must have required data
$sess=JFactory::getSession();
if(!$sess->get("regs1.data")){
	$app = JFactory::getApplication();
	$app->redirect(JRoute::_('index.php?option=com_users&view=registration'));
}

JHtml::_('behavior.keepalive');
//JHtml::_('behavior.formvalidation');
$db			=& JFactory::getDBO();
$params=JComponentHelper::getParams('com_questions');

$lowcost=$params->get("price1");$lowtxt="Pakke 1";
$medcost=$params->get("price2");$medtxt="Pakke 2";
$hicost=$params->get("price3");$hitxt="Pakke 3";
$fitcost=$params->get("price4");$fittxt="Fitness Pakke";
$fee=$params->get("memberfee");
?>
<h2 class="titlepage">Vælg pakke og betal</h2>
<h3 class="title-step-page">Dit abonnement 2/5</h3>  
<div class="eachBox creater-user-box clearfix">
	<div class="cont-box">
		<form name="reg_form2" id="member-registration" action="index.php" method="post" class="form-validate clearfix" enctype="multipart/form-data">
			<div class="wrapCreaterUser step-4">
				<div class="col-info-1 start-up">
					<?php
					$db->setQuery("SELECT * FROM #__content WHERE id=18");
					$row = $db->loadObject();
					?>
					<div class="col-box">
						<?php echo $row->introtext;?>
					</div>

					<div class="eachForm form-select-package">
						<?php echo $row->fulltext;?>
						<div class="cnt-package clearfix">
							<div class="wrap-m-table">
								<table class="table-step4 m-table">
									<colgroup>
										<col id="ppack1">
										<col id="ppack2" style="background:#EEE">
										<col id="ppack3">
										<col id="ppack4">
									</colgroup>
									<tbody>
										<tr>
											<th>
												Slanke  <br> Pakke 1
											</th>
											<th>
												Slanke  <br> Pakke 2
											</th>
											<th>
												Slanke  <br> Pakke 3
											</th>
											<th>
												Fitness <br> Pakke
											</th>
										</tr>
										<tr>
											<td>
												<a onclick="select_package(1)">
													<strong>
														Kr. <?php echo $lowcost?>,-
													</strong>
													<span>
														Pr. måned
													</span>
												</a>
											</td>
											<td>
												<a onclick="select_package(2)">
													<strong>
														Kr. <?php echo $medcost?>,-
													</strong>
													<span>
														Pr. måned
													</span>
												</a>
											</td>
											<td>
												<a onclick="select_package(3)">
													<strong>
														Kr. <?php echo $hicost?>,-
													</strong>
													<span>
														Pr. måned
													</span>
												</a>
											</td>
											<td>
												<a onclick="select_package(4)">
													<strong>
														Kr. <?php echo $fitcost?>,-
													</strong>
													<span>
														Pr. måned
													</span>
												</a>
											</td>
										</tr>
									</tbody>
								</table><!-- m-table  -->
							</div><!--wrap-m-table -->
							<div class="wrap-m-table2">
								<table class="table-step4 m-table2">
									<colgroup>
										<col>
										<col id="fpack1">
										<col id="fpack2">
										<col id="fpack3">
										<col id="fpack4">
									</colgroup>
									<tbody>
										<?php
										$db->setQuery("SELECT a.*,
											(SELECT b.published FROM #__questions_core b WHERE a.title=b.title AND b.catid=11) published2,
											(SELECT c.published FROM #__questions_core c WHERE a.title=c.title AND c.catid=12) published3,
											(SELECT d.published FROM #__questions_core d WHERE a.title=d.title AND d.catid=16) published4
											FROM #__questions_core a
											WHERE catid=10");
										$rows = $db->loadObjectList();
										?>
										<?php
										foreach($rows as $row)
										{
											?>
											<tr class="odd">
												<td class="t-col-all" colspan="4">
													<div>
														<div class="tool-tip tooltip" title="<?php echo htmlspecialchars(nl2br($row->text));?>">
															<img src="templates/fitplan/src_mobile/images/iconTooltip.png" alt="">
														</div>
														<span class="namePack">
															<?php echo $row->title;?>
														</span>
													</div>
												</td>
											</tr>
											<tr class="even">
												<td class="t-col-1">
													<?php
													if($row->published == 1):?>
													<img src="templates/fitplan/src_mobile/images/checkRed.png" alt="">
													<?php endif;?>
												</td>
												<td class="t-col-2">
													<?php
													if($row->published2 == 1):?>
													<img src="templates/fitplan/src_mobile/images/checkRed.png" alt="">
													<?php endif;?>
												</td>
												<td class="t-col-3">
													<?php
													if($row->published3 == 1):?>
													<img src="templates/fitplan/src_mobile/images/checkRed.png" alt="">
													<?php endif;?>
												</td>
												<td class="t-col-4">
													<?php
													if($row->published4 == 1):?>
													<img src="templates/fitplan/src_mobile/images/checkRed.png" alt="">
													<?php endif;?>
												</td>
											</tr>
											<?php
										}?>
										<tr class="none">
											<td class="t-col-1">
												<a class="bntBuynow" onclick="select_package(1)">
													Køb nu!
												</a>
											</td>
											<td class="t-col-2">
												<a class="bntBuynow" onclick="select_package(2)">
													Køb nu!
												</a>
											</td>
											<td class="t-col-3">
												<a class="bntBuynow" onclick="select_package(3)">
													Køb nu!
												</a>
											</td>
											<td class="t-col-4">
												<a class="bntBuynow" onclick="select_package(4)">
													Køb nu!
												</a>
											</td>
										</tr>
									</tbody>
								</table><!-- m-table2  -->
							</div><!--wrap-m-table2-->
							<div class="wrap-m-table3">
								<table class="table-step4 m-table3">
									<tbody>
										<tr class="none">
											<td class="t-col-1">
												<h6>
													Vælg tilkøb (valgfrit)
												</h6>
											</td>
											<td class="t-col-2">
												Pris
											</td>
											<td class="t-col-3">
												Vælg ekstra
											</td>
										</tr>
										<?php
										$db->setQuery("SELECT * FROM #__questions_core WHERE catid=15");
										$rows = $db->loadObjectList();
										$i    = 0;$j    = 1;
										foreach($rows as $row)
										{
											?>
											<tr <?php
 if($i) echo "class='even'"?>>
												<td class="t-col-1">
													<div>
														<div class="tool-tip tooltip" title="<?php echo htmlspecialchars(nl2br($row->text));?>">
															<img src="templates/fitplan/src_mobile/images/iconTooltip.png" alt="">
														</div>
														<span class="namePack">
															<?php echo $row->title;?>
														</span>
													</div>
												</td>
												<td class="t-col-2">
													Kr. <?php echo $row->parent?>,-
												</td>
												<td class="t-col-3">
													<input type="checkbox" name="jform[options]" onclick="select_options(<?php echo $j?>)" value="<?php echo $row->parent?>">
												</td>
											</tr>
											<?php
											$i = 1 - $i;$j++;
										}?>

									</tbody>
								</table><!--m-table3-->
							</div><!--wrap-m-table3-->
						</div><!--cnt-package-->
					</div><!--form-select-package-->
				</div><!--col-info-1-->
				<div class="col-info-2">
					<div class="eachForm form-shopping">
						<h5 class="tit">
							<span class="icontit">
								<img src="templates/fitplan/src_mobile/images/iconMembership.png">
							</span>
							<span class="nametit">
								Min indkøbskurv
							</span>
						</h5>
						<h6>
							Du har valgt:
							<span class="color-in ca01b68">
								<?php echo $medtxt?>
							</span>
						</h6>
						<div class="eachRow eaeaea clearfix">
							<div class="left">
								Medlemskab
							</div>
							<div class="right ca01b70">
								Kr. <?php echo $medcost?>,-
							</div>
						</div>
						<div class="eachRow clearfix">
							<div class="left">
								Opstartsgebyr *
							</div>
							<div class="right">
								Kr. <?php echo $fee?>,-
							</div>
						</div>
						<?php
						//make use last $rows
						$i = 0;$j = 1;
						foreach($rows as $row)
						{
							?>
							<div class="eachRow clearfix opt<?php echo $j?> hide">
								<div class="left">
									<?php echo $row->title;?>
								</div>
								<div class="right">
									Kr. <?php echo $row->parent?>,-
								</div>
							</div>
							<?php
							$i = 1 - $i;$j++;
						}?>
						<div class="eachRow rowboil clearfix">
							<div class="left">
								Til betaling om 14 dage *
							</div>
							<div class="right ca01b71">
								Kr. <?php echo $medcost + $fee?>,-
							</div>
						</div>
					</div>  <!--.form-shopping-->
					<div class="eachForm form-">
						<div class="innerFormbtn">
							<label class="label-acp">
								<input type="checkbox" id="agreeterm" onclick="docalc()">
								<span id="agreetxt">
									Jeg har læst og accepteret
								</span>
								<a class="color-in" href="<?php echo JRoute::_('index.php?option=com_content&view=article&id=5&Itemid=104')?>" target="_blank">
									abonnementsvilkår
								</a>
							</label>
							<p>
								Indtast evt. rabatkode:
							</p>
							<div class="eachRow eachInput rowDiscode clearfix">
								<input class="txtip" name="jform[cp]">
							</div>
						</div>
					</div>  <!--.form- -->
					<div class="wrap-btnCheckout">
						<a class="btnGreen btnCheckout" onclick="if(!$('#agreeterm').is(':checked')){$('#agreetxt').css('border','2px solid red');return false;}document.reg_form2.submit()">
							GÅ TIL BETALING
						</a>
					</div>
					<?php
					$db->setQuery("SELECT title, introtext text FROM `#__content` WHERE id IN(8,10)");
					$txt = $db->loadObjectList();
					?>
					<div class="eachForm form-how">
						<h5 class="tit">
							<span class="icontit">
								<img src="templates/fitplan/src_mobile/images/iconHow.png">
							</span>
							<span class="nametit">
								Opstartsgebyr
							</span>
						</h5>
						<?php echo $txt[1]->text?>
					</div>  <!--.form-how-->
					<div class="eachForm form-mail">
						<h5 class="tit">
							<span class="icontit">
								<img src="templates/fitplan/src_mobile/images/iconMail.png">
							</span>
							<span class="nametit">
								Kundeservice
							</span>
						</h5>
						<?php echo $txt[0]->text?>
					</div>  <!--.form-mail-->
				</div><!--col-info-2-->
			</div><!--wrapCreaterUser-->
			<div class="wrap-btn-cru clearfix">
				<a class="btnGreen bntNext bntPrevious left" href="index.php?option=com_users&view=registration">
					<span class="iconext">
						<img src="templates/fitplan/src_mobile/images/iconBack.png">
					</span>FORRIGE
				</a>
			</div>
			<input type="hidden" name="jform[basecost]" value=<?php echo $medcost?> />
			<input type="hidden" name="jform[no]" value=2 />
			<input type="hidden" name="jform[options_nam]" id="options_nam" value="" />
			<input type="hidden" name="jform[total_nam]" id="total_nam" value="<?php echo $medcost + $fee?>" />

			<input type="hidden" name="option" value="com_users" />
			<input type="hidden" name="task" value="registration.step5" />
			<?php echo JHtml::_('form.token');?>
		</form>
	</div><!-- cont-boX-->
</div>
<script type="text/javascript">
var mark=2;
function getbyname(n){
	return document.reg_form2.elements[n];
}

function select_package(no){
	var txt, cost;
	if(!no)
		return;
	switch(no){
	case 1:
	$(".ca01b68")
	cost=<?php echo $lowcost?>;		txt="<?php echo $lowtxt?>";
	break;
	case 2:
	cost=<?php echo $medcost?>;		txt="<?php echo $medtxt?>";
	break;
	case 3:
	cost=<?php echo $hicost?>;		txt="<?php echo $hitxt?>";
	break;
	case 4:
	cost=<?php echo $fitcost?>;		txt="<?php echo $fittxt?>";
	break;
	}
	$("#ppack"+no).css("background", "#EEE");
	if(mark){
		$("#ppack"+mark).css("background", "transparent");
	}
	mark=no;
	$(".ca01b68").html(txt);
	$(".ca01b69").html('Kr. '+cost+',-');
	getbyname("jform[basecost]").value=cost;
	getbyname("jform[no]").value=no;
	docalc();
}
/*function select_time(x){
	getbyname("jform[length]").value=x;
	docalc();
}*/
function select_options(no){
	if(!no)
		return;
	selectedoptions=[];
	indexoptions=[];
	$("input[name='jform[options]']").each(function(i){
	if($(this).is(":checked")){
		indexoptions.push(i+1);
		selectedoptions.push(parseInt($(this).val()));
		$(".opt"+no).show();
	}else
		$(".opt"+(i+1)).hide();
	$('#options_nam').val(indexoptions);
	});
	docalc();
}
function docalc(){
	var base		=getbyname("jform[basecost]").value;
	var course	=1;//getbyname("jform[length]").value;
	var fee		=<?php echo $fee?>;
	cost=base*course;//cost with discount
	/*if(course==3)
	cost-=48;
	else if(course==6)
	cost-=295;
*/
	options=0;//opts calculation
	try{
	$.each(selectedoptions,function(i,v){
	options+=v;
	})
	}catch(ex){}
	//console.log( options);
	total=cost+options;
	total+=fee;

	$(".ca01b70").html("Kr. "+cost+",-");
	$(".ca01b71").html("Kr. "+total+",-");
	$("#total_nam").attr('value', total);
}
</script>